# -*- coding: utf-8 -*-
# coding by liuyunfei 
# 2021-4-12
import cv2
from PyQt5.QtGui import QPixmap,QImage



def cv2img_to_Qpixmap(frame):
    """
     opencv image to QPixmap image (Qt)
    """
    if len(frame.shape) == 2:
        cvRGBImg = cv2.cvtColor(frame,cv2.COLOR_GRAY2RGB)
    elif len(frame.shape) == 3:
        cvRGBImg = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    h,w,c = cvRGBImg.shape
    cvRGBImg = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    qimg = QImage(cvRGBImg.data, w, h, c*w, QImage.Format_RGB888)
    pixmap01 = QPixmap.fromImage(qimg)
    pix = QPixmap(pixmap01)
    return pix


